/*************************************************************************
 Copyright (C) Unpublished Unis Software, Inc. All rights reserved.
 Unis Software, Inc., Confidential and Proprietary.

 This software is subject to copyright protection
 under the laws of the Public of China and other countries.

 Unless otherwise explicitly stated, this software is provided
 by Unis "AS IS".
 *************************************************************************/
package com.unis.service.car;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.unis.common.util.TemplateUtil;
import com.unis.common.util.TimeUtil;
import com.unis.dao.IDataSet4iBatis;
import com.unis.model.BaseModel;
import com.unis.model.car.CarApply;

/**
 * @author CSJ (email:raulcsj@163.com)
 * @since 2013-01-11
 */
@Service("carapplyService")
public class CarApplyServiceImpl implements CarApplyService {

    private IDataSet4iBatis iDataSet4iBatis;

    /****************************************
     * Insert a instace of CarApply
     ****************************************/
    public void insert(CarApply carapply) throws Exception {
        carapply.setApplyid(TemplateUtil.genUUID());
        carapply.setApplydate(TimeUtil.getNow());
        iDataSet4iBatis.insert(carapply);
    }

    /****************************************
     * Update a instace of CarApply
     ****************************************/
    public void update(CarApply carapply) throws Exception {
        iDataSet4iBatis.update(carapply);
    }

    /****************************************
     * Delete a instace of CarApply
     ****************************************/
    public void delete(CarApply carapply) throws Exception {
        iDataSet4iBatis.delete(carapply);
    }

    /****************************************
     * Insert instaces of SysUser
     ****************************************/
    public void batchInsert(CarApply carapply) throws Exception {
        throw new RuntimeException("Not yet implement!");
    }

    /****************************************
     * Delete instaces of SysUser
     ****************************************/
    public void batchDelete(CarApply carapply) throws Exception {
        String statementId = carapply.getStatmentId();
        String mainId = carapply.getId();
        String[] ids = mainId.split(",");
        List<BaseModel> carapplyList = new ArrayList<BaseModel>();
        for (String id : ids) {
            CarApply model = new CarApply();
            model.setStatmentId(statementId);
            model.setId(id.trim());
            carapplyList.add(model);
        }
        iDataSet4iBatis.batchDelete(carapplyList);
    }

    /****************************************
     * Query instaces of CarApply
     ****************************************/
    public List<BaseModel> queryAsList(CarApply carapply) throws Exception {
        String queryListStatement = "";
        if (carapply.isPaging()) {
            queryListStatement = carapply.getStatmentId();
            carapply.setStatmentId("CarApply.queryRecordsCount");
            BaseModel baseModel = iDataSet4iBatis.queryAsObject(carapply);
            carapply.setTotalCount(baseModel.getTotalCount());
            carapply.setStatmentId(queryListStatement);
        }
        return iDataSet4iBatis.queryAsList(carapply);
    }

    /****************************************
     * Query a instaces of CarApply
     ****************************************/
    public BaseModel queryAsObject(CarApply carapply) throws Exception {
        return iDataSet4iBatis.queryAsObject(carapply);
    }

    @Resource
    public void setiDataSet4iBatis(IDataSet4iBatis iDataSet4iBatis) {
        this.iDataSet4iBatis = iDataSet4iBatis;
    }
}
